// 文件路径：com.huaxin.device.dto.enums.InsulationLevel.java
package com.huaxin.device.dto.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.huaxin.hxenum.base.BaseCodeEnum;

/**
 * 绝缘等级枚举 (Insulation Class)
 * 表示电气设备绝缘材料耐热等级
 */
public enum InsulationLevel implements BaseCodeEnum<String> {

    Y("Y", "Y级"),
    A("A", "A级"),
    E("E", "E级"),
    B("B", "B级"),
    F("F", "F级"),
    H("H", "H级"),
    C("C", "C级");

    @EnumValue
    private final String code;
    private final String displayName;

    InsulationLevel(String code, String displayName) {
        this.code = code;
        this.displayName = displayName;
    }

    @JsonValue
    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDisplayName() {
        return displayName;
    }

    public static InsulationLevel of(String code) {
        if (code == null || code.trim().isEmpty()) return null;
        for (InsulationLevel level : values()) {
            if (level.getCode().equalsIgnoreCase(code.trim())) {
                return level;
            }
        }
        return null;
    }

    public static boolean isValid(String code) {
        return of(code) != null;
    }
}